<template>
    <div class="tab-control">
        <div v-for="(item,index) in titles" 
            :key="index" 
            @click="itemClick(index)"
            :class="{active:index == currenIndex}"
            class="tab-control-item">
            <span>{{item}}</span>
        </div>
    </div>
</template>
<script>
import {ref} from 'vue'
export default {
    name:"TabControl",
    props:{
        titles: {
            type:Array,
            default(){
                return [];
            }
        }
    },
    setup(props,{emit}){
        // 声明当前属性
        let currenIndex = ref(0);
        // 添加事件为属性添加类名,index是每个的下标
        const itemClick = (index) =>{
            currenIndex.value = index;
            emit('tabClick',index);
        }
        return{
            currenIndex,
            itemClick
        }
    }
}
</script>
<style scoped lang="scss">
    .tab-control{
        height: 40px;
        line-height: 40px;
        display: flex;
        text-align: center;
        font-size: 14px;
        background-color: #FFFFFF;
        width: 100%;
        position: sticky;
        top: 44px;
        z-index: 10;
        .tab-control-item{
            flex: 1;
            span{
                padding: 5px;
            }
        }
        // 激活
        .active {
            color: var(--color-tint);
            span{
                border-bottom: 3px solid var(--color-tint);
            }
        }
    }
</style>
